/**
 * 
 */
package com.icon.jsf;

import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Connection;
import java.util.List;

import javax.faces.event.ActionEvent;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.icon.dto.Data;
import com.icon.utils.Queries;
import com.icon.utils.Utils;

/**
 * @author jonathanxuya
 *
 */
public class MantBean implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public MantBean() {
	}
	
	Utils utils = new Utils();
	
	private List data;
	private Data selectedData;
	/**
	 * @return the data
	 */
	public List getData() {
		try {
			Connection con = utils.getConnectionBD();
			try{
				QueryRunner qr = new QueryRunner();
				ResultSetHandler blh = new BeanListHandler(Data.class);
				data = (List) qr.query(con,Queries.QUERY_DATA_PRINCIPAL,blh);
			} catch (Exception ex1){
				ex1.printStackTrace();
			}
		} catch (Exception ex){
			ex.printStackTrace();
		}
		
		return data;
	}
	/**
	 * @param data the data to set
	 */
	public void setData(List data) {
		this.data = data;
	}
	
	/**
	 * @return the selectedData
	 */
	public Data getSelectedData() {
		if(selectedData == null){
			selectedData = new Data();
		}
		return selectedData;
	}
	/**
	 * @param selectedData the selectedData to set
	 */
	public void setSelectedData(Data selectedData) {
		this.selectedData = selectedData;
	}
	
	public String updateData(){
		System.out.println("Actualizar data..."+selectedData.getNombre());
		return "mantenimiento";
	}
	
	public void deleteData (){
		System.out.println("Eliminar data..."+ selectedData.getNombre());
		
	}
	
}
